#ifndef DOWNLOADTASK_H
#define DOWNLOADTASK_H

#include <widget/dataprogress.h>

#include <QFile>



struct DownloadInfo
{
    QFile* file;
    QString user;
    QString filename;
    QString md5;
    QUrl url;
    bool isDownload;
    DataProgress* dp;
    bool isShare;
};

class DownloadTask
{
public:
    static DownloadTask* getInstance();
    bool isEmpty();
    bool isDownload();
    bool isShareTask();
    DownloadInfo* takeTask();
    void dealDownloadTask();

    int appendDownloadList(FileInfo* info, QString filePathName, bool isShare = false);
private:
    DownloadTask() = default;
    ~DownloadTask() = default;
    DownloadTask(const DownloadTask& obj) = delete;
    DownloadTask& operator=(const DownloadTask& obj) = delete;
    DownloadTask(DownloadTask&& obj) = delete;
    DownloadTask& operator=(DownloadTask&& obj) = delete;

    static DownloadTask* instance;
private:
    class AutoRelease
    {
    public:
        AutoRelease() = default;
        ~AutoRelease()
        {
            if(instance == nullptr) return;
            delete instance;
            instance = nullptr;
        }
    };
private:
    static AutoRelease _at;

    QList<DownloadInfo*>list;
};

#endif // DOWNLOADTASK_H
